package com.xmut.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.product.annotation.CheckJwt;
import com.xmut.mall.product.searchparam.ManagerSkuComponentsSearchParam;
import com.xmut.mall.product.searchparam.SkuComponentsSearchParam;
import com.xmut.mall.product.searchparam.SkuPageSearchParam;
import com.xmut.mall.product.utils.RespBean;
import com.xmut.mall.product.vo.EditSkuVo;
import com.xmut.mall.product.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.product.entity.SkuInfoEntity;
import com.xmut.mall.product.service.SkuInfoService;
import com.xmut.mall.product.utils.PageUtils;
import com.xmut.mall.product.utils.R;



/**
 * sku信息
 *
 * @author 1912120131suntingxing
 * @email 1192081604@qq.com
 * @date 2022-07-14 00:45:33
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 商品详情页点击立即购买 也就是BuyNow模式获取商品交易详情
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getGoodPayDetailTypeBuyNow")
    public RespBean getGoodPayDetailTypeBuyNow(@RequestBody Map<String,Object> param){
        return skuInfoService.getGoodPayDetailTypeBuyNow(param);
    }

    /**
     * 获取商城官方管理端的平台券所用的sku选择组件的分页数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getManagerSkuComponentsDataByPage")
    public RespBean getManagerSkuComponentsDataByPage(@RequestBody ManagerSkuComponentsSearchParam param){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return skuInfoService.getManagerSkuComponentsDataByPage(vo,param);
    }

    /**
     * 根据参数获取商城官方管理端的sku礼物信息
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getManagerSkuGiftByParams")
    public RespBean getManagerSkuGiftByParams(@RequestBody Map<String,Object> params){
        return skuInfoService.getManagerSkuGiftByParams(params);
    }

    /**
     * 获取sku选择组件的分页数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getSkuComponentsDataByPage")
    public RespBean getSkuComponentsDataByPage(@RequestBody SkuComponentsSearchParam param){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return skuInfoService.getSkuComponentsDataByPage(vo,param);
    }

    /**
     * 根据参数获取Sku赠品
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getSkuGiftByParams")
    public RespBean getSkuGiftByParams(@RequestBody Map<String,Object> params){
        return skuInfoService.getSkuGiftByParams(params);
    }

    /**
     * 删除Sku
     * @param skuId
     * @return
     */
    @CheckJwt
    @DeleteMapping("/deleteSku/{skuId}")
    public RespBean deleteSku(@PathVariable Long skuId){
        return skuInfoService.deleteSku(skuId);
    }

    /**
     * 编辑Sku
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("/editSku")
    public RespBean editSku(@RequestBody EditSkuVo vo){
        return skuInfoService.editSku(vo);
    }

    /**
     * 获取sku的分页数据
     * @return
     */
    @CheckJwt
    @PostMapping("/getSkuByPage")
    public RespBean getSkuByPage(@RequestBody SkuPageSearchParam searchParam){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(searchParam,vo);
        return skuInfoService.getSkuByPage(vo,searchParam);
    }

    @GetMapping("/getSkuInfoById/{skuId}")
    public RespBean getSkuInfoById(@PathVariable Long skuId){
        SkuInfoEntity entity = skuInfoService.getById(skuId);
        return RespBean.success("获取成功",entity);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
